<?php

declare(strict_types=1);

namespace app\api\model;

use app\common\model\Product;
use app\common\model\PublicStatus;
use app\common\model\Shop;
use think\Model;

/**
 * @mixin \think\Model
 */
class UserHistory extends Model
{


    //产品关联表
    public function product(){
        return $this->belongsTo(Product::class,'product_id');
    }
    //足迹
    public static function insertHistory($product_id,$combo_id, $user_id,$type=1)
    {
        $data = [
            'product_id' => $product_id,
            'user_id' => $user_id,
            'combo_id'=>$combo_id,
            'type'=>$type
        ];

        if($type == PublicStatus::PUBLIC_STATUS_ONE){
            $row = self::where($data)->whereDay('create_time')->find();
            if (!$row) {
                return self::create($data);
            }
        }else{
            return self::create($data);
        }
    }
}
